//
//  MyBidJobDetailViewModel.swift
//  ezyform
//
//  Created by MoennigQ on 7/1/19.
//  Copyright © 2019 Client.Solution Pty Ltd. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON
class ServcieDetailService: BaseService {
    
    func getMyBidJobDetail(_ id: String, cacheFlag: Bool = true){
        
        let alRequest = ALRequest.init(mainURL: APIConfig.getRequestAPIForV2(APIConfig.BidJobDetailAPI,id: id), method: .get, headers: RequestConstant.AuthTokenParam, paramDict: nil, successBlock: {(obj, _) -> Void in
            if let responseData = obj as? [String : Any], let data = ServiceDetailModel.deserialize(from: responseData){
                ServiceDetailModelHelper.shared.serviceDetailModel.copyAllValuesOfModel(data)
                self.returnBlock(obj, nil)
            }else{
                self.errorBlock?("", "Convert response to ServiceDetailModel faild")
            }
            
        }) {(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest(cacheFlag: cacheFlag)
    }
    
    func getQuestionList(_ id: String){
        
        let alRequest = ALRequest.init(mainURL: APIConfig.getRequestAPIForV2(APIConfig.QuestionListAPI,id: id), method: .get, headers: RequestConstant.AuthTokenParam, paramDict: nil, successBlock: {(obj, _) -> Void in
            self.returnBlock(obj, nil)
            
        }) {(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest()
    }
    func getHistoryList(_ id: String){
        let alRequest = ALRequest.init(mainURL: APIConfig.getRequestAPIForV2(APIConfig.HistoryListAPI,id: id), method: .get, headers: RequestConstant.AuthTokenParam, paramDict: nil, successBlock: {(obj, _) -> Void in
            self.returnBlock(obj, nil)
            
        }) {(code, obj) -> Void in
            self.errorBlock(code,obj)
        }
        alRequest.startRequest()
    }
    func startJob(_ location: String){
        
        let params: Parameters = ["id": ServiceDetailModelHelper.shared.serviceDetailModel.id ,
                                  "location": location]
        
        let alRequest = ALRequest.init(mainURL: APIConfig.getRequestAPIForV2(APIConfig.StartBidJobAPI), method: .post, headers: RequestConstant.AuthTokenParam, paramDict: params, successBlock: {(obj, _) -> Void in
            self.returnBlock(obj, nil)
            
        }) {(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest()
    }
    
    func finishJob(){
        let params: Parameters = ["id": ServiceDetailModelHelper.shared.serviceDetailModel.id]
        
        let alRequest = ALRequest.init(mainURL: APIConfig.getRequestAPIForV2(APIConfig.FinishBidJobAPI), method: .post, headers: RequestConstant.AuthTokenParam, paramDict: params, successBlock: {(obj, _) -> Void in
            self.returnBlock(obj, nil)
            
        }) {(code, obj) -> Void in
            self.errorBlock?(code, obj)
        }
        alRequest.startRequest()
    }
}
